package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.ManagementModel;
import com.example.rbacmanage.service.app.ManagementModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/background/mangementmodel")
public class ManagementModelController {

    @Autowired
    private ManagementModelService managementModelService;
    @GetMapping("/page")
    public Result page(ManagementModel managementModel){
        return Result.success(managementModelService.getPage(managementModel));
    }

    @GetMapping("/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(managementModelService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('background:mangementmodel:add')")
    @PostMapping("/add")
    public Result add(@RequestBody ManagementModel managementModel){
        managementModelService.save(managementModel);
        return Result.success();
    }
    @PreAuthorize("hasAnyAuthority('background:mangementmodel:update')")
    @PutMapping("/update")
    public Result update(@RequestBody ManagementModel managementModel){
        managementModelService.update(managementModel);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:mangementmodel:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        managementModelService.remove(ids);
        return Result.success();
    }
}
